package com.pdg.mcplugin.tsa;

import java.util.logging.Logger;

import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;

import com.iCo6.iConomy;

public class TSAServerListener extends ServerListener{

	//plugin
	private TSA plugin;
	public TSA getPlugin(){
		return plugin;
	}

	//logger
	public Logger getLogger(){
		return getPlugin().getLogger();
	}
	
	//economy
	private iConomy economy; 
	public iConomy getEconomy(){
		return economy;
	}
	
	//constructor
	public TSAServerListener(TSA thePlugin){
		plugin = thePlugin;
	}
	
	//disable plugin
	public void onPluginDisable(PluginDisableEvent event){
		if(economy!=null && event.getPlugin().getDescription().getName().equals(Constants.pluginIConomy)){
			economy = null;
			getLogger().info(Constants.messageIConomyUnhooked);
		}
	}
	
	//enable plugin
	public void onPluginEnable(PluginEnableEvent event){
		if(economy==null){
			Plugin iConomy = getPlugin().getPluginManager().getPlugin(Constants.pluginIConomy);
			if(iConomy!=null && iConomy.isEnabled() && iConomy.getClass().getName().equals(Constants.classNameIConomy)){
				economy = (iConomy)iConomy;
				getLogger().info(Constants.messageIConomyHooked);
			}
		}
	}
}
